package ru.cod.rs.objects.gameobjects;

import ru.cod.rs.interfaces.Game;
import ru.cod.rs.objects.Direction;

public abstract class MoveableUnit extends AbstractUnit {
	protected Velocity vel;
	protected int xDest;

	public MoveableUnit(Side side, Game game) {
		super(side, game);

		vel = new Velocity(2, Direction.Right);
		xDest = game.getGraphics().getWidth() - getWidth();

		if (side.equals(Side.ENEMY)) {
			vel.setDirection(Direction.Left);
			xDest = 0;
		}
	}

	@Override
	public void update() {
		if (Math.abs(x - xDest) >= Math.abs(vel.value())) {
			x += vel.value();
		}
	}

}
